<?php

namespace App\Admin\Exports;

use App\Model\CoinLog;
use App\Model\User;
use App\Model\UserProfile;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class UserCoinExport extends ExcelExporter implements WithMapping, WithHeadings, ShouldAutoSize
{
    protected $fileName = '用户账号信息.xlsx';
    public function headings(): array
    {
        return [
            '用户ID',
            '昵称',
            '注册时间',
            '最后活跃时间',
            '设备ID',
            '充值账户余额(RMB元)'
        ];
    }

    public function map($data): array
    {
        return [
            $data->userProfile->user_profile_id,
            $data->userProfile->nick_name,
            (string)$data->create_at,
            (string)$data->updated_at,
            $data->userItem->device_id,
            (int) $data->recharge_coin/10,
        ];
    }
}
